Click here to return to the VHDL Reference Guide. | (last edit: 24. september 2012) | ||||||||||
Constant declarationA constant is used to give a name to a value, in order to make code easier to read and maintain.Syntaxconstant-declaration -> constant identifier { ',' identifier } ':'' subtype-indication [ ':=' Expression]';' --------------------------------------------------------------------------------------------------- subtype-indication -> [resolution-function-name] type-name [ range-contraint | index-constraint ] Exampleconstant Width: POSITIVE := 8; constant Mask: STD_LOGIC_VECTOR := "0001000011111"; -- Range determined by length of string Rules and CommentsThe value of a constant is defined at declaration and cannot be changed using an assignment statement.The value of a constant can only be read. A constant can be declared using the so called deferred constant declaration. It is then declared and named in the package declaration, but gets its value first in the package body. This coding style hides the value of the constant, it is not shown in the package declaration, and the user is not tempted to use the value directly. Another advantage is if the value of the constant is modified. Then only the package body needs to be recompiled. Placement
See AlsoAlias, Variable |